#include"queue.hpp"

//------------------------------------------
//function about listdata     --------------
//------------------------------------------

void ListData::init()
{
    std::cin>>a;
    std::cin>>b;
}

bool ListData::operator==(ListData& comData)
{
   if(this->a==comData.a&&this->b==comData.b)
   { 
        return 1;
   }
   else {
   return 0;
   }
}

void ListData::operator=(ListData* data)
{
   this->a=data->a;
   this->b=data->b;
}


void ListData::show()
{

    std::cout<<a<<" "<<b<<"\n";
}



//------------------------------------------
//function about Sequencequeue--------------
//------------------------------------------

SequenceQueue::SequenceQueue(int sz)
:size(sz)
{
    this->data=new ListData[size];
    front=0;
    rear=0;
}

void SequenceQueue::Clear()
{
  front=0;
  rear=0;
}


int SequenceQueue::GetLength()
{
   return ((rear-front+size)%size);
}


ListData SequenceQueue::GetHead()
{
  if(rear!=front)
  {
    return data[front];
  }
  else
  {
    std::cout<<"error!empty queue";
  }
}

void SequenceQueue::QueueIn(ListData& a)
{
   if(((rear+1)%size)!=front)
   {
    data[rear]=a;
    rear=((rear+1)%size);
   }
   else
   {
    std::cout<<"error!too much data!";
   }
}


void SequenceQueue::QueueOut()
{
  if(rear!=front)
  {
    front=((front+1)%size);
  }
  else
  {
    std::cout<<"error!empty queue";
  }
}


SequenceQueue::~SequenceQueue()
{
  delete[] data;
}